package com.ruoyi.project.access.controller;

import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.project.access.domain.*;
import com.ruoyi.project.access.service.EnterpriseBasicInfoService;
import com.ruoyi.project.system.domain.SysUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Random;

@RestController
@RequestMapping("/rest/data/management/enterprise")
public class EnterpriseBasicInfoController {
    @Autowired
    private EnterpriseBasicInfoService enterpriseBasicInfoService;

    @GetMapping("/basic/infos/query/picture")
    public EnterpriseBasicInfos getEnterpriseBasicInfosToPicture(String chainType, String scenario, String product){
        return enterpriseBasicInfoService.getEnterpriseBasicInfosByNameToPicture(chainType, scenario, product);
    }

    @GetMapping("/human/resource/query/picture")
    public HumanResourceInfos getHumanResourceInfoToPicture(String chainType, String scenario, String product){
        return enterpriseBasicInfoService.getHumanResourceInfoByNameToPicture(chainType, scenario, product);
    }

    @GetMapping("/status/infos/query/picture")
    public BusinessStatusInfos getBusinessStatusInfoToPicture(String chainType, String scenario, String product){
        return enterpriseBasicInfoService.getBusinessStatusInfosByNameToPicture(chainType, scenario, product);
    }

    @GetMapping("/basic/infos/query")
    public EnterpriseBasicInfos getEnterpriseBasicInfos(int limit, int offset, String chainType, String scenario, String product, String statement) {
        return enterpriseBasicInfoService.getEnterpriseBasicInfosByName(limit, offset, chainType, scenario, product, statement);
    }

    @GetMapping("/human/resource/infos/query")
    public HumanResourceInfos getHumanResourceInfos(int limit, int offset, String chainType, String scenario, String product, String statement) {
        return enterpriseBasicInfoService.getHumanResourceInfosByName(limit, offset, chainType, scenario, product, statement);
    }

    @GetMapping("/business/status/infos/query")
    public BusinessStatusInfos getBusinessStatusInfos(int limit, int offset, String chainType, String scenario, String product, String statement) {
        return enterpriseBasicInfoService.getBusinessStatusInfosByName(limit, offset, chainType, scenario, product, statement);
    }

    @GetMapping("/material/management/infos/query")
    public MaterialManagementInfos getMaterialManagementInfos(int limit, int offset, String chainType, String scenario, String product, String statement) {
        return enterpriseBasicInfoService.getMaterialManagementInfos(limit, offset, chainType, scenario, product, statement);
    }//

    @GetMapping("/production/capacity/infos/query")
    public ProductionCapacityInfos getProductionCapacityInfos(int limit, int offset, String chainType, String scenario, String product, String statement) {
        return enterpriseBasicInfoService.getProductionCapacityInfos(limit, offset, chainType, scenario, product, statement);
    }

    @GetMapping("/sale/capacity/infos/query")
    public SaleCapabilityInfos getSaleCapabilityInfos(int limit, int offset, String chainType, String scenario, String product, String statement) {
        return enterpriseBasicInfoService.getSaleCapabilityInfos(limit, offset, chainType, scenario, product, statement);
    }

    @GetMapping("/chain/type/query")
    public List<String> getChainType(){
        return enterpriseBasicInfoService.getChainTypeByName();
    }

    @GetMapping("/scenario/query")
    public List<String> getScenario(String chainType){
        SysUser user = SecurityUtils.getLoginUser().getUser();
        String userName = user.getUserName();
        System.out.println(userName);
        if(Objects.equals(userName, "admin")) {//是系统用户
            return enterpriseBasicInfoService.getScenario(chainType);
        }
        else {//企业用户
            return enterpriseBasicInfoService.getPartScenario(chainType,userName);//获取部分数据
        }
    }

    @GetMapping("/query/product")
    public List<String> getProduct(String chainType, String scenario) {
        SysUser user = SecurityUtils.getLoginUser().getUser();
        String userName = user.getUserName();
        if(Objects.equals(userName, "admin")) {//是系统用户
            return enterpriseBasicInfoService.getProduct(chainType, scenario);
        }
        else {
            return enterpriseBasicInfoService.getPartProduct(chainType, scenario,userName);
        }
    }

    @PostMapping("/action/delete")
    public void deleteEnterprises(@RequestParam String chainType, @RequestParam String scenario, @RequestBody List<String> enterprises) {
        enterpriseBasicInfoService.deleteEnterprises(chainType, scenario, enterprises);
    }
}
